"""
date: 2018/09/16
"""
import re


def convert(t):
    """
    function: 把字符串中的字典取出来。
    :param t: 包含字典信息的字符串。
    :return: 字典。
    """
    ss = s[1:len(s) - 1]
    s2 = [x for x in ss]
    s3 = []
    for i in s2:
        if i != "," and i != "{" and i != "}" and i != " ":
            s3.append(i)
    s4 = {}
    temp = key = ""
    mark = 1
    for i in s3:
        if i == "'" and mark == 1:
            mark = 2
            continue
        if i == "'" and key == "" and mark == 2:
            mark = 3
        if i == "'" and key != "" and mark == 2:
            mark = 4
        if i != "'" and mark == 2:
            temp += i
            continue
        if i == ":":
            mark = 1
            continue
        if mark == 3:
            key = temp
            temp = ""
            continue
        if mark == 4:
            s4[key] = temp
            key = temp = ""
            mark = 1
            continue
        pass
    return s4
    pass


def convert2(t):
    """
    function: 用正则实现convert函数。
    :param t:
    :return:
    """
    return re.findall(r'\w+', t)
    pass

if __name__ == '__main__':
    s = "[{'a1':'44', 'b':'lisi','sc':'33'}]"
    print(s)
    ss = convert2(s)
    print(ss)
